package com.example.zxlwork.recemmend.fagment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.zxlwork.R;
import com.example.zxlwork.adapter.RecGridViewAdapter;
import com.example.zxlwork.object.RecObj;

import java.util.ArrayList;
import java.util.List;

public class recFragment extends Fragment {

    //获取gridview控件对象
    private GridView recommendgv;
    //创建内容列表容器
    private List<RecObj> reclist;
    //初始化适配器
    private RecGridViewAdapter recGridViewAdapter;





    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View recPage = inflater.inflate(R.layout.recommend_fragment_rec,null);

        //在这里设置recommend_fragment_rec.xml中的内容

        //1.获取gridview控件对象
        recommendgv = recPage.findViewById(R.id.recommend_gv);
        //2.初始化list中的内容，使用外置item实现
        reclist = new ArrayList<>();
        RecObj obj1 = new RecObj(R.drawable.jzh,"hello my friend");
        reclist.add(obj1);
        RecObj obj2 = new RecObj(R.drawable.ry,"hello ry");
        reclist.add(obj2);
        RecObj obj3 = new RecObj(R.drawable.zym,"hello zym");
        reclist.add(obj3);
        RecObj obj4 = new RecObj(R.drawable.zxl,"hello zxl");
        reclist.add(obj4);
        RecObj obj5 = new RecObj(R.drawable.zxl,"hello zxl");
        reclist.add(obj5);
        RecObj obj6 = new RecObj(R.drawable.zxl,"hello zxl");
        reclist.add(obj6);




        //3.给gridview绑定适配器
        //实例化适配器
        recGridViewAdapter = new RecGridViewAdapter(
                getActivity(),
                R.layout.recommend_fragment_rec_item,
                reclist
        );
        //绑定适配器
        recommendgv.setAdapter(recGridViewAdapter);



        return recPage;


    }
}
